﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using SqlCon;


        //用户切换
namespace yfxt
{
    public partial class xt_yhqh : Form
    {
        public xt_yhqh()
        {
            InitializeComponent();
        }

        //string str1=null;
        //string str2=null;
        //string str3=null;
        #region 退  出
        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        #endregion

        #region 登  陆  
        private void button1_Click(object sender, EventArgs e)
        {
            DataTable dt = new DataTable();
            
            //将textbox数据传送给SQL语句，获取用户数据
            string sqlstr = "select ygmm,ygdm,ygxm,ygbh,ygjb from gy_ygdm where ygbh='" + textBox1.Text.ToString() + "' and ygmm='" + textBox2.Text.ToString() + "'";
            dt.Load(SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, sqlstr, null));

            if (this.textBox1.Text.Trim() == "")
            {
                MessageBox.Show("请输入工号");
            }
            else            
            {
                //判断是否存在用户，并将员工工号和姓名赋值给全局变量ygxm，ygbh
                if (dt.Rows.Count > 0)
                {
                    Program.ygxm = dt.Rows[0]["ygxm"].ToString();
                    Program.ygbh = dt.Rows[0]["ygbh"].ToString();
                    Program.ygjb = dt.Rows[0]["ygjb"].ToString();
                    if (Program.ygjb.CompareTo("普通员工") != 0)
                    {
                        //用户维护ToolStripMenuItem.Enabled = true;
                        //药品信息维护ToolStripMenuItem.Enabled = true;
                        //科室限制维护ToolStripMenuItem.Enabled = true;
                        //出入库方式维护ToolStripMenuItem.Enabled = true;
                    }
                    this.Close();
                }
                else
                {
                    MessageBox.Show("密码错误，请重新输入");
                }
                //mainform form = new mainform(str1,str2,str3);
                //form.main_Load(sender, e);
            }
        }
        #endregion

        #region  加载函数
        private void xt_yhqh_Load(object sender, EventArgs e)
        {
            //this.KeyPreview = true;
            textBox1.Focus();
        }
        #endregion

    }
}
